<template>
  <ion-page>
    <ion-tabs>
      <ion-router-outlet></ion-router-outlet>
      <ion-tab-bar slot="bottom" class="modern-tab-bar">
        <ion-tab-button tab="tab1" href="/tabs/home" class="tab-button">
          <div class="tab-content">
            <ion-icon :icon="homeOutline" class="tab-icon" />
            <ion-label class="tab-label">书城</ion-label>
          </div>
        </ion-tab-button>

        <ion-tab-button tab="tab2" href="/tabs/type" class="tab-button">
          <div class="tab-content">
            <ion-icon :icon="gridOutline" class="tab-icon" />
            <ion-label class="tab-label">书架</ion-label>
          </div>
        </ion-tab-button>

        <ion-tab-button tab="tab3" href="/tabs/my" class="tab-button">
          <div class="tab-content">
            <ion-icon :icon="personOutline" class="tab-icon" />
            <ion-label class="tab-label">我的</ion-label>
          </div>
        </ion-tab-button>
      </ion-tab-bar>
    </ion-tabs>
  </ion-page>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { IonTabBar, IonTabButton, IonTabs, IonLabel, IonIcon, IonPage, IonRouterOutlet } from '@ionic/vue';
import { images, homeOutline, personOutline, gridOutline } from 'ionicons/icons';
import { Storage } from '@ionic/storage';
import { postAction } from '@/api/manage';
import app from "../main"

export default defineComponent({
  name: 'TabsPage',
  components: { IonLabel, IonTabs, IonTabBar, IonTabButton, IonIcon, IonPage, IonRouterOutlet },
  setup() {
    return {
      images,
      homeOutline,
      gridOutline,
      personOutline
    }
  },
  created() {
    this.initStore();
  },
  methods: {
    async initStore() {
      const storage = new Storage();
      await storage.create();
      const username = await storage.get('username');
      const password = await storage.get('password');
      if (username && password) {
        postAction('user/login', { username: username, password: password }).then((res) => {
          if (res.data.message === '失败') {
          } else {
            app.config.globalProperties.$currentUser = res.data.user;
          }
        });
      }
    }
  }
});
</script>

<style lang="less" scoped>
.modern-tab-bar {
  --background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
  border-radius: 20px 20px 0 0;
  padding: 8px 0;
  height: 80px;
}

.tab-button {
  --color: #9ca3af;
  --color-selected: #4f46e5;
  --ripple-color: transparent;
  border-radius: 12px;
  margin: 0 8px;
  transition: all 0.3s ease;

  &.tab-selected {
    transform: translateY(-2px);
    
    .tab-content {
      background: rgba(79, 70, 229, 0.1);
      border-radius: 12px;
      padding: 8px 12px;
    }
    
    .tab-icon {
      transform: scale(1.1);
      color: #4f46e5;
    }
    
    .tab-label {
      color: #4f46e5;
      font-weight: 600;
    }
  }
}

.tab-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  padding: 4px 8px;
}

.tab-icon {
  font-size: 24px;
  margin-bottom: 4px;
  transition: all 0.3s ease;
}

.tab-label {
  font-size: 12px;
  font-weight: 500;
  transition: all 0.3s ease;
  margin: 0;
}

@media (prefers-color-scheme: dark) {
  .modern-tab-bar {
    --background: rgba(30, 41, 59, 0.95);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .tab-button {
    --color: #64748b;
    --color-selected: #6366f1;
    
    &.tab-selected .tab-content {
      background: rgba(99, 102, 241, 0.2);
    }
  }
}
</style>
